﻿using System;

namespace Gonte
{
    /// <summary>
    /// A template pair
    /// </summary>
    /// <typeparam name="T1"></typeparam>
    /// <typeparam name="T2"></typeparam>
    public class Tuple<T1, T2>
    {
        #region Constructors

        public Tuple(T1 first, T2 second)
        {
            ExceptionThrower.ThrowWhenNull("first", first);
            ExceptionThrower.ThrowWhenNull("second", second);

            first_ = first;
            second_ = second;
        } 

        #endregion

        public T1 First
        {
            get { return first_; }
        }

        public T2 Second
        {
            get { return second_; }
        } 

        #region Methods

        public override int GetHashCode()
        {
            return first_.GetHashCode() ^ second_.GetHashCode();
        }

        public static bool operator == (Tuple<T1, T2> a, Tuple<T1, T2> b)
        {
            return Object.ReferenceEquals(a, b) ||
                (Object)a != null && a.Equals(b);
        }

        public static bool operator != (Tuple<T1, T2> a, Tuple<T1, T2> b)
        {
            return !(a == b);
        }

        public override bool Equals(Object obj)
        {
            Tuple<T1, T2> tuple = obj as Tuple<T1, T2>;

            return
                tuple != null &&
                tuple.first_.Equals(this.first_) &&
                tuple.second_.Equals(this.second_);
        }

        public override string ToString()
        {
            return string.Format("First: {0}, Second: {1}", first_, second_);
        } 

        #endregion

        #region Fields

        private readonly T1 first_;
        private readonly T2 second_;

        #endregion
    }
}
